package org.aalku.springTest.launcher;

import java.util.Collection;

import org.aalku.springTest.service.ServiceOne;
import org.springframework.context.support.GenericXmlApplicationContext;

public class ContinuousTestClientLauncher {

	private static GenericXmlApplicationContext context;

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		context = new GenericXmlApplicationContext("application-context-test-client.xml");
		
		while (true) {
			try {
				System.out.println("RMI");
				test(100000, context.getBean("serviceOneR", ServiceOne.class));
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				System.out.println("Hessian");
				test(100000, context.getBean("serviceOneH", ServiceOne.class));
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println();
			System.out.println();
			System.err.println();
			System.err.println();
			Thread.sleep(1000);
		}
	}

	private static void test(int size, ServiceOne serviceOne) {
		for (int i = 0; i < 1; i++) {
			long t0 = System.nanoTime();
			Object res = serviceOne.test(size);
			long t1 = System.nanoTime();
			System.out.print(((Collection<?>) res).size());
			System.out.print("  ");
			System.out.println(String.format("%.2f ms", (t1-t0)/1000000d));
		}
	}

	public static GenericXmlApplicationContext getGenericXmlApplicationContext() {
		return context;
	}

}
